<template>
  <div class="header">
    <div class="l-content">
      <el-button
        size="small"
        style="width: 30px; height: 30px"
        type="success"
        @click="handleCollapse"
      >
        <el-icon color="#409efc" size="20">
          <Share />
        </el-icon>
      </el-button>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-if="current" :to="current.path"
          >{{ current.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <img :src="getImageUrl('user')" alt="" class="user" />
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handelLonginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useAllDataStore } from '@/stores/header.js'
import { useRouter } from 'vue-router'
import { Share } from '@element-plus/icons-vue'

const getImageUrl = () => {
  return new URL(`../assets/user.jpg`, import.meta.url).href
}
const store = useAllDataStore()
const handleCollapse = () => {
  store.state.isCollapse = !store.state.isCollapse
}
const router = useRouter()
const handelLonginOut = () => {
  store.clean()
  router.push('/login')
}
const current = computed(() => store.state.currentMenu)
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #333;
}

.icons {
  width: 20px;
  height: 20px;
}

.l-content {
  display: flex;
  align-items: center;
  margin-left: 20px;

  .el-button {
    margin-right: 10px;
  }
}

.r-content {
  margin-right: 40px;

  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%; // 变圆角
  }
}

// 通过 :deep() 穿透 scoped 样式，
// 修改 Element Plus 组件内部元素样式，将文字颜色改为白色并添加点击效果
//:deep(.bread span) {
//  color: #fff !important;
//  cursor: pointer !important;
//}
</style>
